<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const p1 = new Promise((resolve, reject) => {
          try {
            console.log("开始请求A.....")
            // throw new Error("网络出现问题!!!!")
            setTimeout(() => {
              console.log("数据请求成功");
              resolve({
                token: "hskahdoqwhdlkash"
              })
            }, 2000)
          } catch (e) {
            reject(e.message)
          }
        })
    
    
        /* 
          Promise的then方法
            - then方法是同步绑定的,但是then中的回调函数是异步的,需要等到调用then的promise实例状态发生改变
            - then方法接收两个回调函数,分别处理成功promise实例和失败promise实例的逻辑
            - then接收的两个回调函数接受两个参数,分别是成功promise的值和失败promise的值
        
        */
        const p2 = p1.then((value) => {
          console.log("成功", value);
        }, (reason) => {
          console.log("失败", reason);
        })
      </script>
</body>
</html>